package cn.mapper;

import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.HashMap;

public class SysUserProvider {
    public String selectAndRole(HashMap<String,Object> map){
        return new SQL(){{
            SELECT(" l.*,rr.name rname,so.name oname ");
            FROM(" sys_user l ");
            LEFT_OUTER_JOIN("sys_user_role r on l.id=r.user_id left join sys_office so on so.id=l.office_id left join sys_role rr on r.role_id=rr.id");
            WHERE(" l.del_flag=0 ");
            if (map.containsKey("phone")&& !StringUtils.isEmpty(map.get("phone"))){
                WHERE(" l.phone like concat('%',#{phone},'%') ");
            }
            if (map.containsKey("name")&& !StringUtils.isEmpty(map.get("name"))){
                WHERE(" l.name like concat('%',#{name},'%')  ");
            }
            if (map.containsKey("rname")&& !StringUtils.isEmpty(map.get("rname"))){
                WHERE(" rr.name like concat('%',#{rname},'%')  ");
            }
            GROUP_BY(" id");
        }}.toString();
    }
}
